<template>
  <swiper :options="swiperOption">
    <swiper-slide v-for="(item, index) of pages" :key="index">
      <div id="icons">
        <div class="icon" v-for="item_ of item" :key="item_.id">
          <a :href="item_.url">
            <div class="icon-img"><img :src="item_.imgUrl" alt="" /></div>
            <p class="tit">{{ item_.tit }}</p>
          </a>
        </div>
      </div>
    </swiper-slide>
    <!-- Optional controls -->
    <div class="swiper-pagination" slot="pagination"></div>
  </swiper>
</template>

<script>
export default {
  name: 'icons',
  props: {
    iconsUrl: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconsUrl.forEach((item, index) => {
        var page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '../../../assets/style/stylus.styl'
  .swiper-pagination >>> .swiper-pagination-bullet
    width: 5px !important;
    height: 5px !important;
  #icons >>> .swiper-pagination-fraction, .swiper-pagination-custom, .swiper-container-horizontal > .swiper-pagination-bullets
    bottom -2px !important
  .swiper-pagination >>> .swiper-pagination-bullet-active
    background-color #00BCD4 !important
  #icons
    width 100%
    overflow hidden
    padding-bottom 0.625rem
    .icon
      float left
      width 25%
      margin-top 0.625rem
      .icon-img
        width 100%
        text-align center
        img
          width 60%
      .tit
        text-align center
        color #212121
        font-size 0.875rem
        padding: 0 0.2rem;
        shenglue()
</style>
